package com.yunhe.rentcars.commons.util;

import org.apache.ibatis.datasource.DataSourceFactory;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * Created by Administrator on 2017/11/9 0009.
 */
public class DruidDataSourceFactory implements DataSourceFactory {

    private Properties properties;

    @Override
    public void setProperties(Properties properties) {
       this.properties = properties;
    }

    @Override
    public DataSource getDataSource() {

        Properties druidConfig = new PropertiesHandler("druid").getProperties();
        this.properties = druidConfig;

        DataSource dataSource = null;
        try {
            dataSource = com.alibaba.druid.pool.DruidDataSourceFactory.createDataSource(druidConfig);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataSource;
    }
}
